// component/amount/amount.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    val: {
      type: Number,
      value: 1
    },
    maxSum: {
      type: Number,
      value: 1
    }

  },

  /**
   * 组件的初始数据
   */
  data: {
    addShow: true
  },
  /**
   * 组件的方法列表
   */
  methods: {
    bindKeyInput(e) {
      const that = this;
      let val = parseFloat(e.detail.value);
      let result = val.toFixed(2)
      that.setData({
        val: result
      })
      var myEventDetail = {
        val: result
      }
      this.triggerEvent('myevent', myEventDetail)
    },
    // 点击加号
    add() {
      const that = this;
      let val = that.data.val;
      val++;
      let result = val.toFixed(2)
      that.setData({
        val: result
      })
      var myEventDetail = {
        val: that.data.val
      }
      this.triggerEvent('myevent', myEventDetail)
    },
    // 点击减号
    minus() {
      const that = this;
      let val = that.data.val;
      if (val <= 1) {
        return false
        // that.setData({
        //   val: 1
        // })
      } else {
        val--;
        let result = val.toFixed(2)
        that.setData({
          val: result
        })
      }
      var myEventDetail = {
        val: that.data.val
      }
      this.triggerEvent('myevent', myEventDetail)
    }
  },
  created() {
    const that = this;
    if (that.data.maxSum == 0) {
      that.setData({
        addShow: false
      })
    } else {
      that.setData({
        addShow: true
      })
    }
  }
})